﻿using System;
using System.Collections.Generic;
using System.Text;
using ChainAnalises.Classes.IntervalAnalysis;
using ChainAnalises.Classes.Statistics.MarkovChain.Generators;

namespace ChainAnalises.Classes.PhantomChains
{
    ///<summary>
    ///</summary>
    public abstract class ITreeNode
    {
        protected List<TreeNode> Children = new List<TreeNode>();
        protected UInt64 volume;
        protected int level;
        protected int StartPosition;

        ///<summary>
        ///</summary>
        ///<returns></returns>
        public abstract bool Decrement();

        public UInt64 Volume
        {
            get { return volume; }
        }

        ///<summary>
        ///</summary>
        public int Level
        {
            get { return level; }
        }
        
        protected void Find(BaseChain Result, IGenerator Generator,PhantomTable Table)
        {
            if (Children.Count!=0)
            {
                double Val = Generator.Next();
                UInt64 CurVal=0;
                for (int i = 0; i < Children.Count; i++)
                {
                    CurVal += Children[i].volume;
                    if (Val <= ((double)CurVal / volume))
                    {
                        Children[i].FillChain(Result, Generator,Table);
                        return;
                    }
                }
            }
            else
            {
                Decrement();
            }
        }

        ///<summary>
        ///</summary>
        ///<param name="index"></param>
        ///<returns></returns>
        public TreeNode GetChild(int index)
        {
            return Children[index];
        }
    }
}
